package com.zadtek.sharkRider.activity.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.zadtek.sharkRider.R;
import com.zadtek.sharkRider.activity.OrderDetailActivity_;
import com.zadtek.sharkRider.activity.common.Common;
import com.zadtek.sharkRider.activity.data.OrderWaitData;

public class OrderWaitAdapter extends CommonAdapter<OrderWaitData> {

	private String formatAddress = "";

	public OrderWaitAdapter(Context context, List<OrderWaitData> datas,
			int layoutId) {
		super(context, datas, layoutId);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void convert(ViewHolders holder, final OrderWaitData t) {
		TextView newtaskmomey = holder.getView(R.id.waitgood_money);
		TextView newtasktime = holder.getView(R.id.waitgood_time);
		TextView newtask_goods_getaddress = holder
				.getView(R.id.wait_goods_getaddress);
		TextView getgpsaddr = holder.getView(R.id.getgpsaddr);

		newtaskmomey.setText("￥" + t.getReturnpay());
		if (!t.getAdd_time().equals("") || t.getAdd_time() != null) {
			newtasktime.setText(Common.getStrTime(t.getAdd_time()));
		}

		try {
			String address_road =t.getAddress_road();
			if (address_road ==null || address_road.equals("") || address_road.equals("null")) {
			String addrss = t.getGps_addrs();
			if (addrss != null && !addrss.equals("")) {
				getgpsaddr.setText(addrss); // 根据经纬度反查地址
				getgpsaddr.setVisibility(View.VISIBLE);
			} else {
				getgpsaddr.setVisibility(View.GONE);
			}
			}else{
				getgpsaddr.setText(address_road); // 根据经纬度反查地址
				getgpsaddr.setVisibility(View.VISIBLE);
			}
		} catch (Exception e) {
		}

		newtask_goods_getaddress.setText(t.getSendaddress());
		LinearLayout submitthread = holder.getView(R.id.submitthread);
		ListView ItemList = holder.getView(R.id.waitgood_itemlist);
		OrderWaitItemAdapter itemadapter = new OrderWaitItemAdapter(mContext,
				t.getOrderItemList(), R.layout.waitgoodlist_itemlist_item,
				t.getMain_id());
		ItemList.setAdapter(itemadapter);

		submitthread.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (t.getMain_id() !=null && !t.getMain_id().equals("")) {
				Intent intent = new Intent(mContext, OrderDetailActivity_.class);
				intent.putExtra("mainid", t.getMain_id());
				intent.putExtra("status", "wait");
				mContext.startActivity(intent);
				}
			}
		});
	}

}
